package com.wengu.game;

import cn.hutool.core.util.RandomUtil;

import java.util.Scanner;

/**
 * 猜数字游戏
 * @author wanghailei
 * @date 2023/01/03
 */
public class GameGuessNumber {
    public static void main(String[] args) {
        System.out.println("==============欢迎来到猜数字游戏=================");
        System.out.println("=============================================");
        System.out.println("===================游戏规则===================");
        System.out.println("电脑随机出一个数字，游戏参与者猜电脑出的数字，并输入，");
        System.out.println("每次猜完后，电脑会提示参与都输入的数字是大了还是小了，");
        System.out.println("然后参与者可继续猜，直到猜对为止");
        int min = 1;
        // 包含
        int max = 99;
        int randomInt = RandomUtil.randomInt(min, max+1);
        Scanner input = new Scanner(System.in);
        while (true){
            System.out.println("请输入数字：");
            int number = input.nextInt();
            if (number < min || number > max){
                System.out.println("请输入100（不包含）以内的正数");
            } else {
                if (number == randomInt){
                    System.out.println("恭喜你，猜对了！");
                    System.out.println(">>>>>>>>>>>>>>>>>>666>>>>>>>>>>>>>");
                    break;
                } else if (number < randomInt){
                    System.out.println("你猜的数字小了");
                } else {
                    System.out.println("你猜的数字大了");
                }
            }
            System.out.println("==========================================");
            System.out.println("==========================================");
        }
    }
}
